<%@page import="java.text.SimpleDateFormat" %>
<%@page import="beans.ResourceSchedule" %>
<%@page import="beans.Person" %>
<%@page import="beans.Project" %>
<%@page import="beans.Resource" %>
<%@page import="beans.Skill" %>

<jsp:useBean id="person" class="beans.Person" scope="session"/>
<jsp:useBean id="resources" type="java.util.List" scope="request"/>
<jsp:useBean id="skills" type="java.util.List" scope="request"/>
<jsp:useBean id="resourceSchedules" type="java.util.List" scope="request"/>
<jsp:useBean id="people" type="java.util.List" scope="request"/>
<jsp:useBean id="projects" type="java.util.List" scope="request"/>
<jsp:useBean id="msg" class="java.lang.String" scope="request"/>

<% 
	SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
%>

<html>
<body>
<% if (msg != null && !"".equals(msg)) { %>
Error: <%=msg %> <br>
<% } %>
Welcome Admin <b><%=person.email%></b>
<p>
<table border="1">
<tr><td>
<h4>Add User</h4>
<form method="post" action="AdminServlet">    
	Email: <input type="text" size="30" name="email"/><br>
	<input type="radio" name="role" value="Unprivileged" checked/>Unprivileged<br>
	<input type="radio" name="role" value="PM"/>Project Manager<br>
	<input type="radio" name="role" value="Admin"/>Admin<br>
	<input type="submit" value="Add User"/><input type="reset"/>
	<input type="hidden" name="act" value="addUser" />
</form>
</td>
<td>
<h4>Add Project</h4>
<form method="post" action="AdminServlet">    
	Title: <input type="text" size="30" name="title"/><br>
	<% for (int i = 0; i < people.size(); i++) { 
	     Person p = (Person) people.get(i);
	     if (p.type == Person.PM) {                 %>
	     <input type="radio" name="pm_id" value="<%=p.id%>"/><%=p.email %><br>
	<%   }                                          %>
	<% }                                            %>
	<input type="submit" value="Add Project"/><input type="reset"/>
	<input type="hidden" name="act" value="addProject" />
</form>
</td></tr>
<tr><td>
<h4>Add Resource</h4>
<form method="post" action="AdminServlet">    
	Description: <input type="text" size="30" name="description"/><br>
	<input type="submit" value="Add Resource"/><input type="reset"/>
	<input type="hidden" name="act" value="addResource" />
</form>
</td>
<td>
<h4>Add Skill</h4>
<form method="post" action="AdminServlet">    
	Description: <input type="text" size="30" name="description"/><br>
	<input type="submit" value="Add Skill"/><input type="reset"/>
	<input type="hidden" name="act" value="addSkill" />
</form>
</td></tr>
</table>

<h4>Resources Schedule</h4>
<table border="1">
<tr><th>Resource</th><th>Start Date</th><th>End Date</th><th>Task</th><th>Project</th></tr>
<%
for(int i = 0; i < resourceSchedules.size(); i++) {
	ResourceSchedule r = (ResourceSchedule)resourceSchedules.get(i);
	String startDate = sf.format(r.startDate.getTime());
	String endDate = sf.format(r.endDate.getTime());
%>
	<tr><td><%=r.resourceDescription%></td><td><%=startDate%></td><td><%=endDate%></td><td><%=r.taskDescription %></td><td><%=r.projectTitle %></td></tr>
<%
}
%>
</table>
<h4>Resources</h4>
<table border="1">
<tr><th>Resource</th></tr>
<%
for(int i = 0; i < resources.size(); i++) {
	Resource r = (Resource)resources.get(i);
%>
	<tr><td><%=r.description%></td></tr>
<%
}
%>
</table>

<form action="AdminServlet" method="post">
<h4>People</h4>
<table border="1">
<tr><th></th><th>Person</th><th>Role</th></tr>
<%
for(int i = 0; i < people.size(); i++) {
	Person p = (Person)people.get(i);
%>

	<tr><td><input type="radio" name="person_id" value="<%= p.id %>"></td><td><%=p.email%></td><td><%=Person.TYPE_ID[p.type]%></td></tr>

<%
}
%>
</table>
<input type="submit" value="Assign Project"/>
<input type="hidden" name="act" value="assignPersonProject_one" />
</form>

<h4>Projects</h4>
<table border="1">
<tr><th>Manager</th><th>Project</th></tr>
<%
for(int i = 0; i < projects.size(); i++) {
	Project p = (Project)projects.get(i);
%>
	<tr><td><%=p.manager.email%></td><td><%=p.title%></td></tr>
<%
}
%>
</table>

<h4>Skills</h4>
<table border="1">
<tr><th>Skill</th></tr>
<%
for(int i = 0; i < skills.size(); i++) {
	Skill s = (Skill)skills.get(i);
%>
	<tr><td><%=s.description%></td></tr>
<%
}
%>
</table>

</body>
</html>